#coding=utf-8
#!/usr/bin/python3
# @author:ZhaiGuiDe
# @Time:2021/6/2/ 9:52

from pymysql import *
from load_video_110_53.Common.common import *
class MysqlClient():
    def __init__(self):
        self.comm = Common()
        # 创建数据库链接
        self.db=connect(host='10.168.103.53',
                          port=3305,
                          db='videodb',
                          user='root',
                          passwd='root',
                          charset='utf8')
        #创建游标
        self.cs1 = self.db.cursor()

    def dataInsert(self):
        #拿到所有的视频路径+名称，存入数据库
        # for name in self.comm.get_all_video_names():
        with open("./name.txt", "r")as f:
            name_lists = f.readlines()
            for name in name_lists:
                print(name)
                insert_sql = """
                            insert into test_video_file(video_name,flag) values("%s","%s")
                        """
                count = self.cs1.execute(insert_sql % (name,0))
                self.db.commit()
        print("视频路径全部存储完毕")

    def dataSelect(self,sql):
        # 查询sql，
        count = self.cs1.execute(sql)
        result = self.cs1.fetchall()
        # print(result)
        return result


    def update_flag(self,video_name):
        update_video_flag_sql = """
            UPDATE `test_video_file` SET flag=1 where video_name="%s";
        """
        count = self.cs1.execute(update_video_flag_sql % (video_name))
        self.db.commit()


if __name__ == '__main__':
    dbc = MysqlClient()
    dbc.dataInsert()
    # dbc.update_flag("14cb7970985400bdc52ce08da60058da.mp4")



    # select_checked_1_sql = """
    # SELECT video_id FROM `tb_video_origin` where checked=1 AND create_by="admin2000";
    # """
    # dbc.dataSelect(select_checked_1_sql)


